package top.zhan.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Zhan
 * @date 2022/10/2 16:43
 */
public class WebSiteFactory {
    /**
     * map里面的key是分类
     */
    private Map<String, ConcreteWebSite> map = new HashMap<>();
    /**
     * 根据key获取分类站点
     * @param category
     * @return
     */
    public CloudWebSite getWebSiteByKey(String category){
        if(map.containsKey(category)){
            return map.get(category);
        } else {
            ConcreteWebSite site = new ConcreteWebSite(category);
            map.put(category, site);
            return site;
        }
    }
    /**
     * 获取分类站点的数量
     * @return
     */
    public int getWebSiteCategorySize(){
        return map.size();
    }
}
